package com.plsData.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.plsDTO.dataObjects.Project;

public class ProjectData extends Data {
//gets list of project per resource
	public ArrayList<Project> getProjectsByEmployeeId(int employeeId) {
		
		ArrayList<Project> projectList = null;
		try {
			Connection dbConnection = null;
			PreparedStatement preparedStatement = null;
			

			if (dbConnection == null) {

				dbConnection = getConnection();

			}
			StringBuffer sb = new StringBuffer();
			sb.append("select project_desc from project inner join resource on resource.project_id = project.project_id inner join employee on resource.employee_id = employee.employee_id where employee.employee_id =?");

			preparedStatement = dbConnection.prepareStatement(sb.toString());
			preparedStatement.setInt(1, employeeId);

			ResultSet result = preparedStatement.executeQuery();
			projectList = new ArrayList<Project>();
			Project projectDetails = new Project();
			
			while (result.next()) {
				projectDetails = new Project();
				projectDetails.setProjectName(result.getString("project_desc"));
				projectList.add(projectDetails);

				
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		return projectList;
	}

}
